﻿using DoNetDrive.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DoNetTool.Common.Core.Model
{
    public class FieldDef
    {
        public string Name;
        public string Type;
        public int Len;
        public string SQLName;

        public void SetValue(string sFieldDetail)
        {
            var stmp = sFieldDetail.Split(',');
            Name = stmp[0].Trim();//.ToLower()
            Type = stmp[1].Trim();
            Len = System.Convert.ToInt32(stmp[2].Trim());
            if (stmp.Length == 4)
                SQLName = stmp[3].Trim();
            else
                SQLName = Name;
        }

        public static List<FieldDef> Split(string sFieldDetails)
        {
            var sTmp = sFieldDetails.Split(new[] { StringUtil.StringNewLine }, StringSplitOptions.RemoveEmptyEntries);
            var oList = new List<FieldDef>(sTmp.Length);
            foreach (var detail in sTmp)
            {
                var f = new FieldDef();
                f.SetValue(detail);
                oList.Add(f);
            }
            return oList;
        }
    }
}
